using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using System.IO.Ports;
using System.Text;

#if MINI
using SecretLabs.NETMF.Hardware.NetduinoMini;
#else
using SecretLabs.NETMF.Hardware.Netduino;
#endif

namespace codebase
{
    public class windowDebug : UI.Window
    {
        UI.Label lMemory;
        UI.Label lFps;
        UI.Label lX;
        UI.Label lY;

        public windowDebug(UI.WindowManager win, int x, int y)
        {
            Initialize(win, x, y);
        }

        public override void Initialize(UI.WindowManager win, int x, int y)
        {
            base.Initialize(win, 16, 7);

            Left = x * screen.CharacterWidth;
            Top = y * screen.CharacterHeight;
            CaptionText = "Debug Data";
            CaptionColor = ColorExtensions.BLACK16;

            lMemory = (UI.Label)Add(UI.Window.ControlTypes.Label, 1, 2);
            lFps = (UI.Label)Add(UI.Window.ControlTypes.Label, 1, 3);
            lX = (UI.Label)Add(UI.Window.ControlTypes.Label, 1, 4);
            lY = (UI.Label)Add(UI.Window.ControlTypes.Label, 1, 5);
        }

        public void updateXY(Point point)
        {
            string tx, ty;

            if (point != null)
            {
                tx = point.x.ToString().PadLeft(3, ' ');
                ty = point.y.ToString().PadLeft(3, ' ');
            }
            else
            {
                tx = "  -";
                ty = "  -";
            }

            lX.Text = "X: " + tx;
            lY.Text = "Y: " + ty;
            lX.Refresh();
            lY.Refresh();
        }

        public void updateDebug(long fps)
        {
            lFps.Text = "FPS:" + fps.ToString().PadLeft(4, ' ');
            lFps.Refresh();

            lMemory.Text = "RAM: " + Debug.GC(false).ToString();
            lMemory.Refresh();
        }
    }
}
